#include "head.h"

// do_ls函数：处理列出当前用户目录的操作
void do_ls(int net_fd, self_defined_pro_t *protect){

    char *username=strtok(protect->message,"=");
    username=strtok(NULL,"&");
    char *path=strtok(NULL,"=");
    path=strtok(NULL,"&");

    char all_path[200] = {0};
    strcat(all_path, "ls ");
    strcat(all_path, username);
    strcat(all_path, path);

    char buf[1024] = {0};
    FILE *pipe = popen(all_path, "r");//读取ll命令的结果
    fread(buf,1, sizeof(buf), pipe);

    self_defined_pro_t *send_mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    send_mes->cmd=200;
    strcpy(send_mes->message, buf);
    send(net_fd,send_mes,sizeof(self_defined_pro_t),MSG_NOSIGNAL);

    free(send_mes);
}
